#' Database tidy information
#'
#' Database contains all information of cohorts.
#' @name database
#' @rdname database
#' @param verbose Whether to print extra information.
#' @param all If `FALSE`, just show cohort level information.
#' @export
#' @examples
#' database(verbose = TRUE)
database = function(all = FALSE, verbose = FALSE) {
  db = cohort_ls(cohorts(verbose = verbose)$cohort, verbose = verbose)
  if (!all) {
    db = unique(db[, !startsWith(colnames(db), "dataset"), with = FALSE])
  }
  db
}

#' @describeIn database Get index data from database
#' @param db `database()` or its subset.
#' @export
database_idx = function(db = database(), verbose = FALSE) {
  rv = list()
  for (i in seq_len(nrow(db))) {
    rv[[i]] = dataset_query_idx(db$dataset.id[i], db$id[i], verbose = verbose)
  }
  names(rv) = db$dataset.id
  rv
}


